home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 January / Disc 3 / Amethyst.iso / rl / build-bin / frm < prev    next >
Encoding:
Text File  |  2002-06-04  |  3.5 KB  |  153 lines

  1. #!/bin/sh
  2. # frm - file remove script
  3. # copyright (c) 2000, joseph cheek, joseph@redmondlinux.org
  4. # released under gpl.
  5. # $1: file to remove.  can be full pathname, relative to build root,
  6. #     or relative to current dir
  7. # ex: frm /opt/redmondLinux/builds/21/myfile
  8. # ex: frm col/install/myfile
  9. # ex: frm myfile
  10. # opts: -q: quiet [don't print status messages]
  11. #       -v: verbose
  12. #       -f: force [N/A in this context]
  13. #       -l: language to add to [default: all languages]
  14.  
  15. # BUG: use getopts instead
  16. LANG=
  17. ERROR=0
  18.  
  19. if [ "n$1" = "n-q" ]; then # -q
  20.   QUIET="-q"
  21.   shift
  22. fi
  23.  
  24. if [ "n$1" = "n-v" ]; then # -v
  25.   VERBOSE="-v"
  26.   shift
  27. fi
  28.  
  29. if [ "n$1" = "n-f" ]; then # -f
  30.   FORCE="(force)"
  31.   shift
  32. fi
  33.  
  34. if [ "n$1" = "n-l" ]; then # -l
  35.   LANG="$2"
  36.   shift
  37.   shift
  38. fi
  39.  
  40. if [ ! -r "$1" ]; then # file doesn't exist
  41. ( echo `basename $0`: can\'t find \"$1\"
  42.   echo
  43.   echo usage: `basename $0` \[-q\] \[-v\] \[-f\] \[-l lang\] file
  44.   echo removes file from redmond linux build system
  45.   echo -q is quiet, ie don\'t print status messages
  46.   echo -v is verbose
  47.   echo -f is force, N/A in this context
  48.   echo -l is language or all if not present ) >&2
  49.   exit 1
  50. fi
  51.  
  52.  
  53. # constants and vars
  54.  
  55. RL_ROOT=/opt/redmondlinux
  56. BUILD_NUM_FILE=$RL_ROOT/builds/CURRENT_BUILD
  57. BUILD_NUM=`cat $BUILD_NUM_FILE`
  58. BUILD_ROOT=$RL_ROOT/builds/$BUILD_NUM
  59. BUILD_ROOT_LEN=$[ `echo $BUILD_ROOT | wc -c` - 0 ]
  60. # gives len of build_root plus 1
  61.  
  62. cd $BUILD_ROOT
  63. LANG_TO_PROCESS=`echo ${LANG}*`
  64. cd -
  65.  
  66. for lang in $LANG_TO_PROCESS; do
  67.  
  68.   CHANGELOG=$BUILD_ROOT/$lang/CHANGELOG
  69.   unset PATH_NAME
  70.  
  71.  
  72. # file checks
  73.  
  74. # full pathname and relative to current dir cases
  75.  
  76.   if [ -r "$1" ]; then # file found
  77.     # get fully qualified file name
  78.     pushd `dirname "$1"` > /dev/null
  79.     PATH_NAME=`pwd`/`basename "$1"`
  80.     popd > /dev/null
  81.   fi
  82.  
  83.  
  84. # relative to build root
  85.  
  86.   if [ -r "$BUILD_ROOT/$lang/$1" ]; then # file found
  87.     # get fully qualified file name
  88.     pushd `dirname "$BUILD_ROOT/$lang/$1"` > /dev/null
  89.     PATH_NAME=`pwd`/`basename "$1"`
  90.     popd > /dev/null
  91.   fi
  92.  
  93.  
  94. # more error checks
  95.  
  96.   if [ "n$PATH_NAME" = "n" ]; then # file doesn't exist
  97.   ( echo `basename $0`: can\'t find \"$1\"
  98.     echo
  99.     echo usage: `basename $0` \[-q\] \[-v\] \[-f\] \[-l lang\] file
  100.     echo removes file from redmond linux build system
  101.     echo -q is quiet, ie don\'t print status messages
  102.     echo -v is verbose
  103.     echo -f is force, N/A in this context
  104.     echo -l is language or all if not present ) >&2
  105.     ERROR=1
  106.   fi
  107.  
  108.   PATH_HEADER=`echo $PATH_NAME | cut -b 1-$BUILD_ROOT_LEN`
  109.  
  110.   if [ "$PATH_HEADER" != "$BUILD_ROOT/" ]; then # not in build root
  111.   ( echo `basename $0`: $1 not in build root
  112.     echo
  113.     echo usage: `basename $0` \[-q\] \[-v\] \[-f\] \[-l lang\] file
  114.     echo removes file from redmond linux build system
  115.     echo -q is quiet, ie don\'t print status messages
  116.     echo -v is verbose
  117.     echo -f is force, N/A in this context
  118.     echo -l is language or all if not present ) >&2
  119.     ERROR=1
  120.   fi
  121.  
  122.  
  123. # perform the rm
  124.  
  125.   [ $VERBOSE ] && echo rm -ri "$PATH_NAME"
  126.   rm -ri "$PATH_NAME"
  127.  
  128.   if [ "$?" -gt 0 ]; then # file rm failed
  129.   ( echo `basename $0`: remove failed
  130.     echo please check permissions and try again ) >&2
  131.     ERROR=1
  132.   fi 
  133.  
  134.  
  135. # update changelog
  136.  
  137.   PATH_FOOTER=`echo $PATH_NAME | cut -b $[ $BUILD_ROOT_LEN + 1 ]-`
  138.   echo - $PATH_FOOTER >> $CHANGELOG
  139.  
  140.   if [ "$?" -gt 0 ]; then # update changelog failed
  141.   ( echo `basename $0`: update changelog failed
  142.     echo check permissions on $CHANGELOG ) >&2
  143.     ERROR=1
  144.   fi 
  145.  
  146.   [ $QUIET ] || tail -n 1 $CHANGELOG
  147.  
  148. done
  149.  
  150. exit $ERROR
  151.